package com.bitcola.security.admin.rest;

import cn.hutool.core.util.ObjectUtil;
import com.bitcola.security.admin.biz.ColaBannerBiz;
import com.bitcola.security.common.msg.AppResponse;
import com.bitcola.security.common.rest.BaseController;
import com.bitcola.entity.ColaAppBanner;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/banner")
public class ColaBannerController extends BaseController<ColaBannerBiz, ColaAppBanner> {

    /**
     * banner列表
     * @return
     */
    @RequestMapping("/list")
    public AppResponse list(){
        //获取所有banner
        List<ColaAppBanner> list = baseBiz.list();
        //返回数据
        return AppResponse.ok().data(list);
    }

    /**
     * 新增或编辑
     * @param banner
     * @return
     */
    @RequestMapping("/modify")
    public AppResponse modify(@RequestBody ColaAppBanner banner){
        Boolean bool = baseBiz.modify( banner);
        if(!bool){
            return AppResponse.error("操作失败");
        }
        return AppResponse.ok();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping("/delete/{id}")
    public AppResponse delete(@PathVariable("id") String id){
        Boolean bool = baseBiz.delete( id);
        if(!bool){
            return AppResponse.error("删除失败");
        }
        return AppResponse.ok();
    }

    /**
     * 详情
     * @param id
     * @return
     */
    @RequestMapping("/detail/{id}")
    public AppResponse detail(@PathVariable("id") String id){
        ColaAppBanner banner = baseBiz.findByCondition( id);
        if(ObjectUtil.isEmpty( banner)){
            return AppResponse.error("banner不存在");
        }
        return AppResponse.ok().data( banner);
    }
}
